package com.ad.admin.androidadapt;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 39466 on 2016/3/23.
 */
public class MyAdapter extends BaseAdapter {

    private List<News> data;
    private LayoutInflater inflater;

    public MyAdapter(Context context ,List<News> data){
        this.data = data;
        inflater = LayoutInflater.from(context);

    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View vg, ViewGroup parent) {
        vg = inflater.inflate(R.layout.news_layout,null);
        ImageView image = (ImageView)vg.findViewById(R.id.image);
        TextView title = (TextView)vg.findViewById(R.id.title);
        TextView content = (TextView)vg.findViewById(R.id.content);
        image.setBackgroundColor(data.get(position).getImage());
        title.setText(data.get(position).getTitle());
        content.setText(data.get(position).getContent());
        content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i("john", data.get(position).getContent());
            }
        });

        return vg;
    }
}
